package com.laiyao.bean;

import com.spring.AOP.DefaultProxyFactory;
import com.spring.springInterface.BeanPostProcessor;
import com.spring.springAnnotation.Component;

@Component
public class laiyaoBeanpost implements BeanPostProcessor {

    private DefaultProxyFactory proxyCreator;


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
       if(beanName.equals("userService")){
           System.out.println("初始化之前执行");
           System.out.println(bean);
       }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws ClassNotFoundException {
        Object proxyIfNecessary = proxyCreator.createProxyIfNeedAop(bean, beanName);
        return proxyIfNecessary;
    }

    @Override
    public void setProxyCreator(DefaultProxyFactory beanFactory) {
        this.proxyCreator = beanFactory;
    }

}
